package com.qianxunclub.redis;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import com.qianxunclub.util.SpringContextUtil;

public class RedisMessge {
	private static RedisTemplate<String,Object> redisTemplate = SpringContextUtil.getBean("redisTemplate");
	private static RedisSerializer<?> serializer; 
	/**
	 * 发布者
	 * @param channel
	 * @param message
	 */
	public static void convertAndSend(String channel, Object message){
		redisTemplate.convertAndSend(channel,message);
	}
	/**
	 * 订阅者
	 * @param message
	 * @param pattern
	 * @return
	 */
	public static Object subscribe(Message message, byte[] pattern){
		serializer = redisTemplate.getValueSerializer();
		return serializer.deserialize(message.getBody());
	}
}
